﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="TSV.Areas.Administration.Models" %>
<script type="text/javascript" src="/Scripts/highslide/highslide.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/highslide/highslide.css" />
<script src="/Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
<%
    CategoryDao catDao = new CategoryDao();
    Category category = (Category)ViewData.Model;
%>
<script type="text/javascript">
    hs.graphicsDir = '/Scripts/highslide/graphics/';
    hs.outlineType = 'rounded-white';
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#CategoryForm").validate({
            debug: false,
            errorElement: "span",
            errorPlacement: function (error, element) {
                error.tooltip({
                    bodyHandler: function () {
                        return error.html();
                    }
                });
                error.insertAfter(element);
            },
            rules: {
                CategoryName: {
                    required: true
                },
                Description:{
                    maxlength: 200
                }
            }
        });
        $("#btnChangePhoto").click(function () {
            var url = "/Administration/Common/UploadImage?controller=<%=Constants.CATEGORY_DEFAULT_VALUE %>&recordID=" + $('#RecordID').val() + "&saveTo=<%=Constants.PHOTO_PATH_ROOT_CATEGORY %>&width=50&height=50";
            JS_LIB.popUpWindow(url, '#Photograph', 'Upload Hình');
            return false;
        });
    });        
</script>
<table width="85%" border="0" cellpadding="0" cellspacing="0" class="edit">
    <tr>
        <td class="label">
            Hình
        </td>
        <td class="input">
            <table>
                <tr>
                    <td>
                        <%
                            string labelPhoto = "<img src='/Content/Images/Common/nopic.gif' height='50px' width='50px' />";
                            if (ViewData.Model == null)
                            {
                                Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(category.Image) || (!string.IsNullOrEmpty(category.Image) && category.Image == Constants.NO_IMAGE))
                                {
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                                else
                                {
                                    labelPhoto = "<a id='thumb1' href='" + Constants.PHOTO_PATH_ROOT_CATEGORY + category.Image
                                                    + "' class='highslide' onclick='return hs.expand(this)'>"
                                                    + "<img id='imgPhoto' src='" + Constants.PHOTO_PATH_ROOT_CATEGORY + category.Image
                                                    + "' alt='Highslide JS' title='Nhấp vào để phóng to' height='50px' width='50px' /></a>";
                                    Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                                }
                            }
                            if (ViewData.Model == null)
                            {
                                Response.Write(Html.Hidden("RecordID", ""));
                                Response.Write(Html.Hidden("Photograph", ""));                                
                            }
                            else
                            {
                                Response.Write(Html.Hidden("RecordID", category.ID));
                                Response.Write(Html.Hidden("ID", category.ID));
                                Response.Write(Html.Hidden("Photograph", category.Image));
                            }                                                        
                        %>
                    </td>
                    <td valign="top">
                        <input type="button" class="upload_image" id="btnChangePhoto" value="" title="Đổi Hình" />
                        <%  string stylePhoto = "display: none";
                            if (ViewData.Model != null)
                            {
                                if (!string.IsNullOrEmpty(category.Image) && category.Image != Constants.NO_IMAGE)
                                {
                                    stylePhoto = "display: block";
                                }
                            }
                        %>
                        <input type="button" id="btnRemoveImage" class="remove_image" style="<%=stylePhoto %>"
                            onclick="JS_LIB.msgConfirmBox('Bạn có chắc là bạn muốn xóa hình?', 450,'JS_LIB.removeImageWithSize(\'<%=Constants.CATEGORY_DEFAULT_VALUE %>\',50,50)','Xóa Hình');"
                            value="" title="Xóa Hình" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Tên Danh Mục <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("CategoryName", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("CategoryName", category.CategoryName, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Danh Mục Cha
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.DropDownList(CommonDataKey.PARENT_CATEGORY, ViewData[CommonDataKey.PARENT_CATEGORY] as SelectList, Constants.PARENT_CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }
                else
                {
                    Response.Write(Html.DropDownList(CommonDataKey.PARENT_CATEGORY, null, Constants.PARENT_CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }                
            %>
        </td>
    </tr>        
    <tr>
        <td class="label" style="vertical-align: top">
            Mô Tả
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextArea("Description", string.Empty, new { @maxlength = "200", @style = "width:400px;height:200px" }));
                }
                else
                {
                    Response.Write(Html.TextArea("Description", CommonFunc.SetHtmlForCKEditor(category.Description), new { @maxlength = "200", @style = "width:400px;height:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>        
        <td colspan=2 align=center>
            <input type="submit" class="save" value="" alt="" />
            <input type="button" class="cancel" value="" alt="" onclick="JS_LIB.redirect('/Administration/Category/Index')" />
        </td>
    </tr>
</table>
